package cn.com.nes.common.util;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.pool.KryoFactory;
import com.esotericsoftware.kryo.pool.KryoPool;
import org.objenesis.strategy.StdInstantiatorStrategy;

public final class KryoUtil {

    public static KryoPool newKryoPool() {
        return new KryoPool.Builder(new KryoFactory() {
            @Override
            public Kryo create() {
                final Kryo kryo = new Kryo();
                kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
                kryo.setClassLoader(getClass().getClassLoader());
                return kryo;
            }
        }).softReferences().build();
    }

}
